package com.example.homelicaisystem.config;

import com.auth0.jwt.exceptions.JWTDecodeException;
import com.auth0.jwt.exceptions.JWTVerificationException;
import com.example.homelicaisystem.entity.exception.UsedCashException;
import com.example.homelicaisystem.entity.exception.WrongEnoughInvestment;
import com.example.homelicaisystem.entity.exception.WrongEnoughMoney;
import com.example.homelicaisystem.utils.Result;

import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * create by 2023/1/9.
 *
 * @author udbjqr
 */
@RestControllerAdvice("com.example.homelicaisystem.control")
@Slf4j
public class ControlAdvice {
	@ResponseStatus(HttpStatus.OK)
	@ExceptionHandler({JWTVerificationException.class,JWTDecodeException.class})
	public Result<?> handleTokenError(JWTVerificationException e) {
//		return Result.err(Result.NOT_LOGIN, e.getMessage(), null);
		return null;
	}

	@ResponseStatus(HttpStatus.OK)
	@ExceptionHandler({WrongEnoughMoney.class})
	public	Result<?> expendErr(WrongEnoughMoney e){
		return Result.err(Result.NOT_ENOUGH_MONEY,e.getMessage(),null);
	}

	@ResponseStatus(HttpStatus.OK)
	@ExceptionHandler({UsedCashException.class})
	public	Result<?> incomeDeleteErr(UsedCashException e){
		return Result.err(Result.USED_CASH,e.getMessage(),null);
	}

	@ResponseStatus(HttpStatus.OK)
	@ExceptionHandler({WrongEnoughInvestment.class})
	public	Result<?> InvestmentNumErr(WrongEnoughInvestment e){
		return Result.err(Result.NOT_ENOUGH_INVESTMENT,e.getMessage(),null);
	}

}

